import time
from vec import *

WIDTH = 500
HEIGHT = 500

BACK_COLOR = (0, 0, 0)

unit = 50

class MyRect:
    def __init__(self, x, y, clr):
        self.x = x
        self.y=y
        self.clr = clr

    def Update(self):
        pass

    def Draw(self):
        rc = Rect((self.x, self.y), (unit, unit))
        screen.draw.filled_rect(rc, self.clr)

lastTime = time.time()
deltaTime = 0
spd = 5
p = 0
pspd = 0.01

now_at=Vec2(0,0)
now_to=Vec2(0,0)
unit = 50

rc = MyRect(0, 0, (100, 0, 0))

def move(start_pt, end_pt):
    global p, rc
    if p < 1.0:
        p += pspd
    else:
        p = 1.0
        has_finished = True
    rc.x = start_pt.x * (1 - p) + end_pt.x * p
    rc.y = start_pt.y * (1 - p) + end_pt.y * p

def on_key_down(key):
    if key == keys.ESCAPE:
        quit()

def on_mouse_move(pos):
    global rc,now_at,now_to
    now_at=(Vec2(rc.x,rc.y))
    now_to=(Vec2(pos[0],pos[1]))
    p=0

def on_mouse_up(pos):
    print("mouse_up", pos)

def update():
    global now_to, now_at,p
    move(now_at, now_to)

def draw():
    screen.clear()
    screen.fill(BACK_COLOR)
    rc.Draw()